
import React from 'react';
import css from './index.less';
import PropTypes from 'prop-types';

export default class InputNum extends React.Component {
  constructor(props) {
    super(props);
  }

  static propTypes = {
    label: PropTypes.any,
    numValue: PropTypes.number,
    type: PropTypes.string,
  };

  static defaultProps = {
    label: '二级标题',
    numValue: 0,
    type: 'text',
  };

  changeNum(e) {
    let val = parseFloat(e.target.value);
    const { mod, label } = this.props;
    mod.changeNum(label, val);
  }
  addNumber() {
    const { mod, label } = this.props;
    mod.addNumber(label);

  }
  decNumber() {
    const { mod, label } = this.props;
    mod.decNumber(label);
  }

  render() {
    const { label, numValue, type } = this.props;
    return (
      <div className={css.wrap}>
        <div className={css.label}>
          {label}
        </div>
        <div className={css.value}>
          <input value={numValue}
                 type={type}
                 onChange={this.changeNum.bind(this)} />
          <div>
            <i onMouseDown={this.addNumber.bind(this)}/>
            <i onMouseDown={this.decNumber.bind(this)}/>
          </div>
        </div>

      </div>
    );
  }
}
